Allocate
Allocate Increase the physical size of an open file short fRefNum ; file reference, as obtained via FSOpen long *byteCount ; bytes to add; receives actual bytes added
Allocate extends the physical size of a file on disk, without changing the file's logical EOF.
fRefNum is the reference number of an open file. See FSOpen and OpenRF. byteCount is the address of a positive long integer. On entry, it specifies how
much space, in bytes, you wish to add to the file's physical allocation.
Upon return, it contains the actual number of bytes added (it will be a
multiple of the disk block size).
noErr (0) No error
dskFulErr (-34) Disk full
fLckdErr (-45) File is locked
fnOpnErr (-38) File not open
ioErr (-36) I/O error
rfNumErr (-51) Bad fRefNum
vLckdErr (-46) Volume is locked
wPrErr (-44) Diskette is write-protected
wrPermErr (-61) Write permission error
Notes: The byteCount parameter is added to the current physical end-of-file, the
sum is rounded up to the size of the next higher allocation block, and the
File Manager attempts to allocate enough blocks to satisfy the request.
If there is not enough free space on the disk, then all available space is
allocated, the byteCount variable is set to the actual number of bytes
allocated, and dskFulErr is returned. Hint: you may wish to shrink the file
back down if the allocation fails (see SetEOF). Note that Allocate works in disk-block size units, with no regard to the logical EOF. For instance:
long byteCount;
short fRef;
byteCount = 1;
Allocate( fRef, &byteCount ); /* add 1 byte to the file */ This attempts to extend the file by 1 byte, but it will always eat up one full
allocation unit (e.g., 512 or 1K) of disk space. Before using Allocate, you may wish to learn the current physical file length by examining the
The PBAllocContig attempts to expand a file by adding contiguous disk blocks to the file (for fastest I/O) SetEOF can also be used to increase file size.